package com.jlastu.androidsx.ui.user;

import android.content.Intent;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.jlastu.androidsx.R;
import com.jlastu.androidsx.adapter.CommunicationAdapter;
import com.jlastu.androidsx.adapter.ICommunicationListener;
import com.jlastu.androidsx.bean.Communication;
import com.jlastu.androidsx.databinding.ActivityCommonBinding;
import com.jlastu.androidsx.model.CommunicationModel;
import com.jlastu.androidsx.ui.WebViewActivity;
import com.jlastu.androidsx.widget.MyItemDecoration;

import cn.project.base.baseui.BaseNormalActivity;

public class XuetangListActivity extends BaseNormalActivity<ActivityCommonBinding> implements ICommunicationListener {

    CommunicationAdapter communicationAdapter;

    private CommunicationModel communicationModel;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_common;
    }

    @Override
    protected void initView() {
        communicationAdapter = new CommunicationAdapter(XuetangListActivity.this,this);
        mBinding.rlCommon.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
        mBinding.rlCommon.addItemDecoration(new MyItemDecoration(10));
        mBinding.rlCommon.setAdapter(communicationAdapter);

        communicationModel = new ViewModelProvider(XuetangListActivity.this).get(CommunicationModel.class);

        communicationModel.getCommunicationList().observe(this,newData->{
            communicationAdapter.setNewData(newData);
            communicationAdapter.notifyDataSetChanged();
        });
    }WebViewActivity

    @Override
    protected void initData() {

    }

    @Override
    public void onCommunicationClick(Communication communication) {
        Intent intent = new Intent(XuetangListActivity.this, WebViewActivity.class);
        intent.putExtra("communication",communication);
        startActivity(intent);
    }
}
